package com.example.demo.service.impl;

import com.example.demo.LoginUser;
import com.example.demo.mapper.BookMapper;
import com.example.demo.mapper.LendRecordMapper;
import com.example.demo.mapper.UserMapper;
import com.example.demo.service.DashboardService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class DashboardServiceImpl implements DashboardService {

    @Resource
    private UserMapper userMapper;
    @Resource
    private LendRecordMapper lendRecordMapper;
    @Resource
    private BookMapper bookMapper;

    @Override
    public Map<String, Object> getDashboardData() {
        int visitCount = LoginUser.getVisitCount();
        Long userCount = userMapper.selectTotalCount();
        Long lendRecordCount = lendRecordMapper.selectTotalCount();
        Long bookCount = bookMapper.selectTotalCount();

        Map<String, Object> map = new HashMap<>();
        map.put("visitCount", visitCount);
        map.put("userCount", userCount);
        map.put("lendRecordCount", lendRecordCount);
        map.put("bookCount", bookCount);

        return map;
    }
}